﻿'*******************************************************************************
'
'  NLocalizer (C) 2010-2012 Chris Prusik (KAP1 Ltd www.kap1.net)
'  The fast, simple solution for localizing .NET applications, by text files.
'  Latest version: http://NLocalizer.codeplex.com/
'
'  $Id$
'
'  This library is free software; you can redistribute it and/or
'  modify it under the terms of the GNU Lesser General Public
'  License as published by the Free Software Foundation; either
'  version 2.1 of the License, or (at your option) any later version.
'
'  This library is distributed in the hope that it will be useful,
'  but WITHOUT ANY WARRANTY; without even the implied warranty of
'  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
'  Lesser General Public License for more details.
'
'*******************************************************************************
Imports NLocalizer
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Public Class MainForm

    Private Sub OpenFileMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenFileMenu.Click
        OpenFileDialog.ShowDialog()
    End Sub

    Private Sub SaveFileMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveFileMenu.Click
        SaveFileDialog.ShowDialog()
    End Sub

    Private Sub BrowseFolderMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrowseFolderMenu.Click
        FolderBrowserDialog.ShowDialog()
    End Sub

    Private Sub ExampleFontMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExampleFontMenu.Click
        FontDialog.ShowDialog()
    End Sub

    Private Sub SelectColorMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectColorMenu.Click
        ColorDialog.ShowDialog()
    End Sub

    Private Sub MessageBoxMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MessageBoxMenu.Click
        MessageBox.Show(Messages.HelloWorld, Messages.TitleInformation, MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub

    Private Sub TestFormMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TestFormMenu.Click
        Using form As New TestForm()
            Try
                Translator.Translate(form)
            Catch ex As Exception
                MessageBox.Show(ex.Message, Messages.TitleError, MessageBoxButtons.OK, MessageBoxIcon.[Error])
            End Try
            form.ShowDialog()
        End Using

    End Sub

    Private Sub LoadLanguagesMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadLanguagesMenu.Click
        Try
            Translator.Translate(Me)
            FillLanguagesMenu()
            LanguageLabel.Text = Translator.Translation.CurrentLanguage
        Catch ex As Exception
            MessageBox.Show(ex.Message, Messages.TitleError, MessageBoxButtons.OK, MessageBoxIcon.[Error])
        End Try
    End Sub

    Private Sub FillLanguagesMenu()
        For Each lang As KeyValuePair(Of String, TranslationClasses) In Translator.Translation
            Dim found As Boolean = False
            For Each item As Object In LanguagesMenu.DropDownItems
                If TypeOf item Is ToolStripMenuItem AndAlso DirectCast(item, ToolStripMenuItem).Text = lang.Key Then
                    found = True
                End If
            Next
            If found = False Then
                LanguagesMenu.DropDownItems.Add(lang.Key)
            End If
        Next
    End Sub

    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadLanguagesMenu_Click(sender, e)
    End Sub

    Private Sub LanguagesMenu_DropDownItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles LanguagesMenu.DropDownItemClicked
        If Translator.Translation.Exists(e.ClickedItem.Text) Then
            Try
                Translator.Translation.CurrentLanguage = e.ClickedItem.Text
                Translator.Translate(Me)
                LanguageLabel.Text = Translator.Translation.CurrentLanguage
            Catch ex As Exception
                MessageBox.Show(ex.Message, Messages.TitleError, MessageBoxButtons.OK, MessageBoxIcon.[Error])
            End Try
        End If
    End Sub
End Class
